#Istio路由管理功能

    #环境
    #rancher v2.4.5 开启istio v1.5.8  开启istio的ignress功能
    #httpbin
    #docker
    #可用的k8s集群

    #在rancher中开启istio并且开启ingress
if [ ! -f "/root/.kube/config" ]; then
  echo '请确认已经将rancher中的kube.config文件复制粘贴到~/.kube/目录下，并重试'
  exit
fi


#开启k8s下命名空间为default的应用自动注入istio功能
kubectl label namespace default istio-injection=enabled

#开启httpbin
kubectl apply -f  route-test/httpbin.yaml

#定义ip跟端口
kubectl get svc istio-ingressgateway -n istio-system

#应用httpbin
kubectl apply -f route-test/httpbin-gateway.yaml
kubectl apply -f route-test/ingressconf.yaml
kubectl apply -f route-test/httpbinconf.yaml

#部署应用
kubectl apply -f route-test/bookinfo.yaml

kubectl apply -f route-test/bookinfo-gateway.yaml

#设置ingress ip与ports
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
export TCP_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].nodePort}')
export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')